package com.ntl.webcore.system.business.controller.monitor;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ntl.webcore.common.annotation.Log;
import com.ntl.webcore.common.enums.BusinessType;
import com.ntl.webcore.system.business.domain.SysErrorLog;
import com.ntl.webcore.system.business.service.ISysErrorLogService;
import com.ntl.webcore.common.core.controller.BaseController;
import com.ntl.webcore.common.core.domain.AjaxResult;
import com.ntl.webcore.common.utils.poi.ExcelUtil;
import com.ntl.webcore.common.core.page.TableDataInfo;

/**
 * 错误日志Controller
 * 
 * 
 * @date 2021-03-31
 */
@Controller
@RequestMapping("/monitor/errorLog")
public class SysErrorLogController extends BaseController
{
    private String prefix = "monitor/errorLog";

    @Autowired
    private ISysErrorLogService sysErrorLogService;

    @RequiresPermissions("monitor:errorLog:view")
    @GetMapping()
    public String errorLog()
    {
        return prefix + "/sysErrorLog";
    }

    /**
     * 查询错误日志列表
     */
    @RequiresPermissions("monitor:errorLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysErrorLog sysErrorLog)
    {
        startPage();
        List<SysErrorLog> list = sysErrorLogService.selectSysErrorLogList(sysErrorLog);
        return getDataTable(list);
    }

    /**
     * 导出错误日志列表
     */
    @RequiresPermissions("monitor:errorLog:export")
    @Log(title = "错误日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysErrorLog sysErrorLog)
    {
        List<SysErrorLog> list = sysErrorLogService.selectSysErrorLogList(sysErrorLog);
        ExcelUtil<SysErrorLog> util = new ExcelUtil<SysErrorLog>(SysErrorLog.class);
        return util.exportExcel(list, "错误日志");
    }

    /**
     * 新增错误日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/addSysErrorLog";
    }

    /**
     * 新增保存错误日志
     */
    @RequiresPermissions("monitor:errorLog:add")
    @Log(title = "错误日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysErrorLog sysErrorLog)
    {
        return toAjax(sysErrorLogService.insertSysErrorLog(sysErrorLog));
    }

    /**
     * 修改 错误日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SysErrorLog sysErrorLog = sysErrorLogService.selectSysErrorLogById(id);
        mmap.put("sysErrorLog", sysErrorLog);
        return prefix + "/editSysErrorLog";
    }

    /**
     * 修改保存 错误日志
     */
    @RequiresPermissions("monitor:errorLog:edit")
    @Log(title = "错误日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysErrorLog sysErrorLog)
    {
        return toAjax(sysErrorLogService.updateSysErrorLog(sysErrorLog));
    }

    /**
     * 删除 错误日志
     */
    @RequiresPermissions("monitor:errorLog:remove")
    @Log(title = "错误日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysErrorLogService.deleteSysErrorLogByIds(ids));
    }

    @RequestMapping("/view/{errorLogId}")
    public String viewSysErrorLog(@PathVariable("errorLogId") String errorLogId, ModelMap mmap){
        SysErrorLog errorLog = sysErrorLogService.selectSysErrorLogById(errorLogId);
        mmap.put("errorLog", errorLog);
        return prefix + "/sysErrorLogInfo";
    }
}
